package top.yekongle.feature.java8.stream;


import org.junit.Ignore;
import org.junit.Test;
import top.yekongle.feature.java8.lambda.Employee;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

@Ignore
public class TestStream4 {

    List<Employee> employees = Arrays.asList(
            new Employee("张三", 18, 5555.55, Employee.Status.FREE ),
            new Employee("李四", 19, 6666.66, Employee.Status.BUSY),
            new Employee("王五", 40, 7777.77, Employee.Status.VOCATION),
            new Employee("赵六", 45, 7777.77, Employee.Status.FREE),
            new Employee("孙七", 60, 7777.77, Employee.Status.VOCATION)
    );



//        给定一个数字列表，如何返回一个由每个数的平方构成的列表
//        给定 [1, 2, 3, 4, 5], 返回 [1, 4, 9, 16, 25]


    
    public void test1() {
        Integer[] nums = new Integer[]{1, 2, 3, 4, 5};
        Stream<Integer> stream = Arrays.stream(nums);
        stream.map((x) -> x * x)
                .forEach(System.out::println);
    }



//        怎样用 map 和 reduce 计算 employee 的个数

    
    public void test2() {
//         Long sum = employees.stream().count();
//         System.out.println(sum);

        Optional<Integer> sum1 = employees.stream().map((e)-> 1).reduce(Integer::sum);
        System.out.println(sum1.get());
    }

}
